﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HippoMapper.DAL.Base
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public abstract class EntityCollectionInterceptAttribute : Attribute
    {
        protected Type _collectionType;

        public Type CollectionType
        {
            get { return _collectionType; }
            set { _collectionType = value; }
        }

        /// <summary>
        /// 待拦截的事件名
        /// </summary>
        public abstract string EventName
        {
            get;
        }

        /// <summary>
        /// 待拦截的容器的类型，例如typeof(EntityCollectionBase<EntityOne>)
        /// </summary>
        /// <param name="collectionName"></param>
        public EntityCollectionInterceptAttribute(Type collectionName)
        {
            this._collectionType = collectionName;
        }
    }

    /// <summary>
    /// 添加拦截器标签
    /// </summary>
    public class EntityCollectionOnAddAttribute : EntityCollectionInterceptAttribute
    {
        public EntityCollectionOnAddAttribute(Type collectionName)
            : base(collectionName)
        {
        }

        public override string EventName
        {
            get { return "OnAddEvent"; }
        }
    }

    /// <summary>
    /// 删除拦截器标签
    /// </summary>
    public class EntityCollectionOnDeleteAttribute : EntityCollectionInterceptAttribute
    {
        public EntityCollectionOnDeleteAttribute(Type collectionName)
            : base(collectionName)
        {
        }

        public override string EventName
        {
            get { return "OnDeleteEvent"; }
        }
    }

    /// <summary>
    /// 清空拦截器标签
    /// </summary>
    public class EntityCollectionOnClearAttribute : EntityCollectionInterceptAttribute
    {
        public EntityCollectionOnClearAttribute(Type collectionName)
            : base(collectionName)
        {
        }

        public override string EventName
        {
            get { return "OnClearEvent"; }
        }
    }
}
